/**
  ******************************************************************************
  * File Name          : route_ec_tonet.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include <string.h>
#include "tskcfg.h"
#include "network.h"
#include "route.h"
#include "cJSON.h"
#include "ctrl_common.h"
#include "storage.h"
#include "collector.h"
#include "dwlcd.h"

#if (ROUTE_INTEGRATED > 0)
void Route_ec_tonet_collector(void)
{
  Route_PayloadType *proute = NULL;
  
  proute = pvPortMalloc(sizeof(Route_PayloadType));
  if(proute != NULL)
  {
    memset(proute, 0, sizeof(Route_PayloadType));
    
    proute->dev_type  = RT_DV_HK;
    proute->trans_dir = ROUTE_TRSDIR_SUBDEV_TO_NET,
    proute->pl_type   = ROUTE_PLTYP_EC_COLLECTOR,
    proute->pl_len    = sizeof(Collector_DataType);
    
    *((Collector_DataType *)(proute->payload)) = Collector_LocalData.average;
      
    if(Route_EvewToNet_Qhd != NULL)
    {
      xQueueSend(Route_EvewToNet_Qhd, proute, 0);
    }
  }
  
	vPortFree(proute);
}

void Route_ec_tonet_fnst(void)
{
  Route_PayloadType *proute = NULL;
  
  proute = pvPortMalloc(sizeof(Route_PayloadType));
  if(proute != NULL)
  {
    memset(proute, 0, sizeof(Route_PayloadType));
    
    proute->dev_type  = RT_DV_HK;
    proute->trans_dir = ROUTE_TRSDIR_SUBDEV_TO_NET,
    proute->pl_type   = ROUTE_PLTYP_EC_STATE_FN,
    proute->pl_len    = sizeof(Ctrl_StateFNType);
    
    *((Ctrl_StateFNType *)(proute->payload)) = Ctrl_StateFN;
      
    if(Route_EvewToNet_Qhd != NULL)
    {
      xQueueSend(Route_EvewToNet_Qhd, proute, 0);
    }
  }
  
	vPortFree(proute);
}

void Route_ec_tonet_slst(void)
{
  Route_PayloadType *proute = NULL;
  
  proute = pvPortMalloc(sizeof(Route_PayloadType));
  if(proute != NULL)
  {
    memset(proute, 0, sizeof(Route_PayloadType));
    
    proute->dev_type  = RT_DV_HK;
    proute->trans_dir = ROUTE_TRSDIR_SUBDEV_TO_NET,
    proute->pl_type   = ROUTE_PLTYP_EC_STATE_SL,
    proute->pl_len    = sizeof(Ctrl_StateSLType);
    
    *((Ctrl_StateSLType *)(proute->payload)) = Ctrl_StateSL;
    
    if(Route_EvewToNet_Qhd != NULL)
    {
      xQueueSend(Route_EvewToNet_Qhd, proute, 0);
    }
  }
  
	vPortFree(proute);
}

void Route_ec_tonet_nqst(void)
{
  Route_PayloadType *proute = NULL;
  
  proute = pvPortMalloc(sizeof(Route_PayloadType));
  if(proute != NULL)
  {
    memset(proute, 0, sizeof(Route_PayloadType));
	
    proute->dev_type  = RT_DV_HK;
    proute->trans_dir = ROUTE_TRSDIR_SUBDEV_TO_NET,
    proute->pl_type   = ROUTE_PLTYP_EC_STATE_NQ,
    proute->pl_len    = sizeof(Ctrl_StateNQType);
    
    *((Ctrl_StateNQType *)(proute->payload)) = Ctrl_StateNQ;
    
    if(Route_EvewToNet_Qhd != NULL)
    {
      xQueueSend(Route_EvewToNet_Qhd, proute, 0);
    }
  }
  
	vPortFree(proute);
}

void Route_ec_tonet_vfst(void)
{
  Route_PayloadType *proute = NULL;
  
  proute = pvPortMalloc(sizeof(Route_PayloadType));
  if(proute != NULL)
  {
    memset(proute, 0, sizeof(Route_PayloadType));
	
    proute->dev_type  = RT_DV_HK;
    proute->trans_dir = ROUTE_TRSDIR_SUBDEV_TO_NET,
    proute->pl_type   = ROUTE_PLTYP_EC_STATE_VF,
    proute->pl_len    = sizeof(Ctrl_StateVFType);
    
    *((Ctrl_StateVFType *)(proute->payload)) = Ctrl_StateVF;
    
    if(Route_EvewToNet_Qhd != NULL)
    {
      xQueueSend(Route_EvewToNet_Qhd, proute, 0);
    }
  }
  
	vPortFree(proute);
}

void Route_ec_tonet_md(void)
{
  Route_PayloadType *proute = NULL;
  
  proute = pvPortMalloc(sizeof(Route_PayloadType));
  if(proute != NULL)
  {
    memset(proute, 0, sizeof(Route_PayloadType));
	
    proute->dev_type  = RT_DV_HK;
    proute->trans_dir = ROUTE_TRSDIR_SUBDEV_TO_NET,
    proute->pl_type   = ROUTE_PLTYP_EC_MD,
    proute->pl_len    = sizeof(Ctrl_ParaMDType);
    
    *((Ctrl_ParaMDType *)(proute->payload)) = Ctrl_ParaMD;
    
    if(Route_EvewToNet_Qhd != NULL)
    {
      xQueueSend(Route_EvewToNet_Qhd, proute, 0);
    }
  }
  
	vPortFree(proute);
}

void Route_ec_tonet_jt(void)
{
  Route_PayloadType *proute = NULL;
  
  proute = pvPortMalloc(sizeof(Route_PayloadType));
  if(proute != NULL)
  {
    memset(proute, 0, sizeof(Route_PayloadType));
	
    proute->dev_type  = RT_DV_HK;
    proute->trans_dir = ROUTE_TRSDIR_SUBDEV_TO_NET,
    proute->pl_type   = ROUTE_PLTYP_EC_JT,
    proute->pl_len    = sizeof(Ctrl_ParaJTType);
    
    *((Ctrl_ParaJTType *)(proute->payload)) = Ctrl_ParaJT;
    
    if(Route_EvewToNet_Qhd != NULL)
    {
      xQueueSend(Route_EvewToNet_Qhd, proute, 0);
    }
  }
  
	vPortFree(proute);
}

void Route_ec_tonet_dl1(void)
{
  Route_PayloadType *proute = NULL;
  
  proute = pvPortMalloc(sizeof(Route_PayloadType));
  if(proute != NULL)
  {
    memset(proute, 0, sizeof(Route_PayloadType));
	
    proute->dev_type  = RT_DV_HK;
    proute->trans_dir = ROUTE_TRSDIR_SUBDEV_TO_NET,
    proute->pl_type   = ROUTE_PLTYP_EC_DL1,
    proute->pl_len    = sizeof(Ctrl_ParaDL1Type);
    
    *((Ctrl_ParaDL1Type *)(proute->payload)) = Ctrl_ParaDL1;
    
    if(Route_EvewToNet_Qhd != NULL)
    {
      xQueueSend(Route_EvewToNet_Qhd, proute, 0);
    }
  }
  
	vPortFree(proute);
}

void Route_ec_tonet_dl2(void)
{
  Route_PayloadType *proute = NULL;
  
  proute = pvPortMalloc(sizeof(Route_PayloadType));
  if(proute != NULL)
  {
    memset(proute, 0, sizeof(Route_PayloadType));
	
    proute->dev_type  = RT_DV_HK;
    proute->trans_dir = ROUTE_TRSDIR_SUBDEV_TO_NET,
    proute->pl_type   = ROUTE_PLTYP_EC_DL2,
    proute->pl_len    = sizeof(Ctrl_ParaDL2Type);
    
    *((Ctrl_ParaDL2Type *)(proute->payload)) = Ctrl_ParaDL2;
    
    if(Route_EvewToNet_Qhd != NULL)
    {
      xQueueSend(Route_EvewToNet_Qhd, proute, 0);
    }
  }
  
	vPortFree(proute);
}

void Route_ec_tonet_sk(void)
{
  Route_PayloadType *proute = NULL;
  
  proute = pvPortMalloc(sizeof(Route_PayloadType));
  if(proute != NULL)
  {
    memset(proute, 0, sizeof(Route_PayloadType));

    proute->dev_type  = RT_DV_HK;
    proute->trans_dir = ROUTE_TRSDIR_SUBDEV_TO_NET,
    proute->pl_type   = ROUTE_PLTYP_EC_SK,
    proute->pl_len    = sizeof(Ctrl_ParaSKType);
    
    *((Ctrl_ParaSKType *)(proute->payload)) = Ctrl_ParaSK;
    
    if(Route_EvewToNet_Qhd != NULL)
    {
      xQueueSend(Route_EvewToNet_Qhd, proute, 0);
    }
  }
  
	vPortFree(proute);
}

void Route_ec_tonet_td(void)
{
  Route_PayloadType *proute = NULL;
  
  proute = pvPortMalloc(sizeof(Route_PayloadType));
  if(proute != NULL)
  {
    memset(proute, 0, sizeof(Route_PayloadType));
	
    proute->dev_type  = RT_DV_HK;
    proute->trans_dir = ROUTE_TRSDIR_SUBDEV_TO_NET,
    proute->pl_type   = ROUTE_PLTYP_EC_TD,
    proute->pl_len    = sizeof(Ctrl_ParaTDType);
    
    *((Ctrl_ParaTDType *)(proute->payload)) = Ctrl_ParaTD;
    
    if(Route_EvewToNet_Qhd != NULL)
    {
      xQueueSend(Route_EvewToNet_Qhd, proute, 0);
    }
  }
  
	vPortFree(proute);
}

#endif
